<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();

if (isset($_POST["uid"]) && isset($_POST["Password"])&&isset($_SESSION["username"])&&($_SESSION["username"]!="")) {
    $id=$_POST["uid"];
    $Password=$_POST["Password"];
    $username=$_SESSION["username"];
    $oldpassword=$database->select("user_text",["[>]pass_key"=>["id"=>"uid"]],["salt","password"],["username"=>$username]);
    $salt=$oldpassword[0]["salt"];
    $oldpassword=$oldpassword[0]["password"];
    $Password=md5($Password);
    $Password=hash("sha512",$Password.$salt);
    $Password=hash("sha512",$Password);
    if($Password==$oldpassword){
        $newgroup=$database->select("user_group",["groupname"],["id"=>$id]);
        $newgroup=$newgroup[0]["groupname"];
        $database->delete("user_group",["id"=>$id]);
        require_once 'getip.php';
        $client_ip = getClientIP();
        $timestamp = time();
        $content = "删除了一个组，组名是：".$newgroup;
        $database->insert("secure_info", ["user" => $username, "ip" => $client_ip, "times" => $timestamp, "content" => $content]);
        echo "<script>alert('删除成功!');location.href='/admin/lsysg.php';</script>";
    }else{
        echo "<script>alert('密码错误!');location.href='/admin/lsysg.php';</script>";
    }}
?>
